<?php
/**
 * Description of Woeid
 *
 * @abstract this helper uses the GeoIP Api
 *
 */
class Zend_Controller_Action_Helper_GetLocationGeoIP extends Zend_Controller_Action_Helper_Abstract {


         function suggest(){

                require_once ( SMANITA_PATH . '/library/GeoIP/geoipcity.inc' );

                /*if (getenv(HTTP_X_FORWARDED_FOR)) {
                    $ip = getenv(HTTP_X_FORWARDED_FOR);
                } else {
                    $ip = getenv(REMOTE_ADDR);
                }*/

                if (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
                    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
                } else {
                    $ip = $_SERVER['REMOTE_ADDR'];
                }

                //$ip = '67.195.114.53'; //yahoo slurp
                //$ip = '66.249.71.206'; //google bot
                //$ip = '90.172.155.159';  // ip movil

                //$gi = geoip_open("C:/GeoIP/GeoLiteCity.dat",GEOIP_STANDARD);
                $gi = geoip_open("/usr/local/share/GeoIP/GeoLiteCity.dat",GEOIP_STANDARD);
                $record = geoip_record_by_addr($gi,$ip);
                //var_dump($record);

                //$result .= $record->region . " " . $GEOIP_REGION_NAME[$record->country_code][$record->region] . "\n";
                $result = "";
                if (isset($record->city)) {
                	$result = $record->city.', ' ;
                	if (isset($record->country_code) && isset($record->region)) { $result .= $GEOIP_REGION_NAME[$record->country_code][$record->region].', ' ;}
                	if (isset($record->country_name)) { $result .= $record->country_name; }
                } else {
                    $result = "";	
                }

                

                geoip_close($gi);

                return $result;

                

        }



}

